๐ Introduction
When you press a key on your keyboard, how does the computer understand it? Computers don't understand letters, numbers, or images the way we do. They convert everything into a language they can process - binary code (0s and 1s).
๐ข Number Systems
A number system is a way of representing numbers using a specific set of symbols (digits). The computer uses four main number systems:
| Number System | Base | Digits Used |
|---|---|---|
| Binary | 2 | 0, 1 |
| Octal | 8 | 0, 1, 2, 3, 4, 5, 6, 7 |
| Decimal | 10 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 |
| Hexadecimal | 16 | 0-9, A, B, C, D, E, F |
1. Binary Number System (Base 2)
Why Binary? Computers use electronic circuits with two voltage levels (high/low), which perfectly match the two binary digits (0 and 1).
Example: The number 13 in decimal = 1101 in binary
1101โ = (1ร2ยณ) + (1ร2ยฒ) + (0ร2ยน) + (1ร2โฐ) = 8 + 4 + 0 + 1 = 13โโ
2. Octal Number System (Base 8)
Uses 8 digits (0-7). Each octal digit can be represented by exactly 3 binary digits.
3. Decimal Number System (Base 10)
This is the number system we use in everyday life with digits 0-9.
4. Hexadecimal Number System (Base 16)
Uses 16 symbols: 0-9 and A-F (where A=10, B=11, C=12, D=13, E=14, F=15)
Why Hexadecimal? It's easier for humans to read than long binary numbers. Each hex digit represents exactly 4 binary digits.
Example: Color codes in web design use hexadecimal: #FF0000 = Red
๐ Number System Conversions
Converting Decimal to Binary
- Divide 25 by 2 = 12 remainder 1
- Divide 12 by 2 = 6 remainder 0
- Divide 6 by 2 = 3 remainder 0
- Divide 3 by 2 = 1 remainder 1
- Divide 1 by 2 = 0 remainder 1
- Read remainders from bottom to top: 11001โ
Converting Binary to Decimal
1101โ = (1ร2ยณ) + (1ร2ยฒ) + (0ร2ยน) + (1ร2โฐ)
= 8 + 4 + 0 + 1 = 13โโ
Binary โ Octal Conversion
Rule: Group binary digits in sets of 3 (from right to left)
Example: 1011101โ to Octal
001 | 011 | 101 = 1 | 3 | 5 = 135โ
Binary โ Hexadecimal Conversion
Rule: Group binary digits in sets of 4 (from right to left)
Example: 10110โ to Hexadecimal
0001 | 0110 = 1 | 6 = 16โโ
๐ Most and Least Significant Positions
Most Significant Digit (MSD) & Least Significant Digit (LSD)
MSD: The leftmost non-zero digit (has the greatest value)
LSD: The rightmost non-zero digit (has the smallest value)
Example: In 3290, MSD = 3, LSD = 9 (not 0)
Most Significant Bit (MSB) & Least Significant Bit (LSB)
Same concept but specifically for binary numbers:
- MSB = 1 (leftmost, value = 2ยณ = 8)
- LSB = 1 (rightmost, value = 2โฐ = 1)
๐พ Data Storage Capacity
Storage Units
| Unit | Value | Description |
|---|---|---|
| Bit | - | Smallest unit (0 or 1) |
| Nibble | 4 bits | Half a byte |
| Byte | 8 bits | Can store one character |
| Kilobyte (KB) | 1024 bytes | About half a page of text |
| Megabyte (MB) | 1024 KB | About 500 pages of text |
| Gigabyte (GB) | 1024 MB | About 500,000 pages |
| Terabyte (TB) | 1024 GB | About 500 million pages |
| Petabyte (PB) | 1024 TB | Massive data centers |
๐ค Coding Systems
Coding systems are standard ways of representing characters (letters, numbers, symbols) as binary numbers.
1. BCD (Binary Coded Decimal)
Uses: 4 bits per decimal digit
Example: 37โโ = 0011 0111 in BCD
Limitation: Can only represent decimal numbers (0-9)
2. ASCII (American Standard Code for Information Interchange)
Uses: 7 bits (can represent 128 characters)
Extended ASCII: 8 bits (256 characters)
Example: 'A' = 65โโ = 1000001โ
Used for: English letters, numbers, basic symbols
3. EBCDIC (Extended Binary Coded Decimal Interchange Code)
Uses: 8 bits (256 characters)
Used in: IBM mainframe computers
Example: 'A' = 11000001โ
4. Unicode
Uses: 16 bits (can represent 65,536 characters)
Supports: All world languages including Sinhala, Tamil, Chinese, Japanese, Arabic, etc.
Example: Sinhala letters, emojis, mathematical symbols
Used in: Modern websites, applications, operating systems
- ASCII: Good for English but can't handle other languages
- Unicode: Universal standard supporting all languages and symbols
๐ Quick Reference Table
| Decimal | Binary | Octal | Hexadecimal |
|---|---|---|---|
| 0 | 0000 | 0 | 0 |
| 1 | 0001 | 1 | 1 |
| 2 | 0010 | 2 | 2 |
| 8 | 1000 | 10 | 8 |
| 10 | 1010 | 12 | A |
| 15 | 1111 | 17 | F |
| 16 | 10000 | 20 | 10 |
๐ Practice Questions & Answers
Convert the decimal number 45โโ to binary.
Steps:
45 รท 2 = 22 remainder 1
22 รท 2 = 11 remainder 0
11 รท 2 = 5 remainder 1
5 รท 2 = 2 remainder 1
2 รท 2 = 1 remainder 0
1 รท 2 = 0 remainder 1
Reading from bottom to top: 101101โ
Convert the binary number 11011โ to decimal.
Calculation:
11011โ = (1ร2โด) + (1ร2ยณ) + (0ร2ยฒ) + (1ร2ยน) + (1ร2โฐ)
= 16 + 8 + 0 + 2 + 1
= 27โโ
How many bits are in 2 Kilobytes?
Calculation:
2 KB = 2 ร 1024 bytes = 2048 bytes
2048 bytes ร 8 bits = 16,384 bits
Convert the hexadecimal number 2Fโโ to binary.
Steps:
2 in hex = 0010 in binary
F in hex = 1111 in binary
Combining: 00101111โ
What is the ASCII code for the letter 'A'?
Note: ASCII uses 7 bits to represent characters. 'A' is represented as decimal 65 or binary 1000001.
Convert octal number 157โ to binary.
Steps:
1โ = 001โ
5โ = 101โ
7โ = 111โ
Combining: 001101111โ
Find the MSD and LSD of the number 3045.07โโ
MSD (Most Significant Digit) = 3
LSD (Least Significant Digit) = 7
Note: MSD is the leftmost non-zero digit, LSD is the rightmost non-zero digit.
Why do computers use the binary number system instead of decimal?
Which coding system should be used to represent Sinhala text in a computer?
Reason: Unicode uses 16 bits and can represent 65,536 different characters, which is sufficient for all world languages including Sinhala, Tamil, Chinese, Japanese, etc. ASCII and EBCDIC can only represent English characters and basic symbols.
Convert hexadecimal A5โโ to decimal.
Calculation:
A5โโ = (A ร 16ยน) + (5 ร 16โฐ)
= (10 ร 16) + (5 ร 1)
= 160 + 5
= 165โโ
๐ก Study Tips
- Practice Conversions: The more you practice converting between number systems, the easier it becomes.
- Remember the Powers: Memorize powers of 2 (2, 4, 8, 16, 32, 64, 128, 256...) for quick binary conversions.
- Use Grouping: When converting binary to octal (group of 3) or hexadecimal (group of 4), always group from right to left.
- Storage Units: Remember that 1 KB = 1024 bytes (not 1000). This is because computers use base 2.
- ASCII Codes: 'A' starts at 65, 'a' starts at 97. The difference is always 32.
- Draw Diagrams: Visual representations help understand how data flows from input to storage.